#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <Judy.h>

#include "globals.h"
#include "limits.h"

// returns the id (index in the concept_names array) of a given
// concept name
int get_cid(unsigned char* cname) {
	Word_t* pvalue;
	
	JSLG(pvalue, concept_names_ids, cname);
	if (pvalue == NULL)
		return -1;
	return *pvalue;
}

// puts the given concept name into concept_names returns its id
int put_cname(unsigned char* cname) {
	PWord_t pvalue;

	if (atomic_concept_count == MAX_CONCEPT_COUNT) {
		fprintf(stderr, "max number of concept names reached, aborting!\n");
		exit(-1);
	}
	JSLI(pvalue, concept_names_ids, cname);
	if (pvalue == PJERR) {
		fprintf(stderr, "could not insert concept name %s, aborting",cname);
		exit(-1);
	}
	*pvalue = atomic_concept_count;
	return atomic_concept_count++;
}

// returns the id (index in the role_names array) of a given role name
int get_rid(unsigned char* rname) {
	Word_t* pvalue;
	
	JSLG(pvalue, role_names_ids, rname);
	if (pvalue == NULL)
		return -1;
	return *pvalue;
}

// puts the given role name into role_names and returns its id
int put_rname(unsigned char* rname) {
	PWord_t pvalue;

	if (role_count == MAX_ROLE_COUNT) {
		fprintf(stderr, "max number of role names reached, aborting!\n");
		exit(-1);
	}
	JSLI(pvalue, role_names_ids, rname);
	if (pvalue == PJERR) {
		fprintf(stderr, "could not insert role name %s, aborting", rname);
		exit(-1);
	}
	*pvalue = role_count;
	return role_count++;
}
